<!DOCTYPE html>
<html>
<head>
    <title>${sysEn}-${pageTitle}</title>
     <#include "/common/com_css.ftl" >
</head>
<body>
    <div id="wrapper">
        <!----左侧导航开始----->
        <#include "/common/menu.ftl">
        <!----左侧导航结束----->

        <!---右侧内容区开始---->
        <div id="page-wrapper" class="gray-bg dashbard-1">
            <#include "/common/con_nav.ftl">
            <@con_nav_tag current=pageTitle></@con_nav_tag>
            <!-- 检索条件开始 -->
            <div class="ibox-content m-b-sm border-bottom">
                <div class="row">
	                 <div class="col-sm-2">
	                        <div class="form-group">
	                           <input type="hidden" name="type" id="type" value="${obj.type}">
	                            <label class="col-form-label" for="prov">省份</label>
	                            <select class="form-control m-b" name="prov" id="prov"  onchange="altCitys()" >
	                            	<option value="">请选择省份...</option>
	                                <#list areaMap ?keys as key>
	 									<option value=${key}>${areaMap[key].name}</option>						
									</#list>
	                            </select>
	                        </div>
	                    </div>
	                 <div class="col-sm-2">
	                        <div class="form-group">
	                            <label class="col-form-label" for="city">城市</label>
	                            <select class="form-control m-b" name="city" id="city" onchange="altAreas()">
	       
	                            </select>
	                        </div>
	                    </div>
                   <div class="col-sm-2">
	                        <div class="form-group">
	                            <label class="col-form-label" for="area">区/县</label>
	                            <select class="form-control m-b" name="area" id="area">
	       
	                            </select>
	                        </div>
                	</div>
                  
                   <div class="col-sm-2">
                        <div class="form-group">
                            <label class="col-form-label" for="name">关键字</label>
                            <input type="text" id="name" name="name" value="" placeholder="" class="form-control">
                        </div>
                    </div>

                </div>
                <div class="text-left">
                    <input type="button" name="" class="btn btn-primary" value="提交" id="btnSubmit"></input>
                </div>
            </div>
            <!-- 检索条件结束 -->
            <div class="row">
                <div class="col-lg-12">
                    <div class="ibox ">
                        <div class="ibox-content">
                            <div class="table-responsive">
                                <table class="table table-striped table-bordered table-hover" id="example" >
                                </table>
                            </div>
                        </div>

                    </div>
                </div>
            </div>
            <#include "/common/footer.ftl">
        </div>
        <!---右侧内容区结束---->
     </div>
    <#include "/common/com_table_js.ftl">
    <script>
        $(document).ready(function() {
            var table =  ListPageManager.DataTable.init({
                ajax:{
                    url:"${ctx}/store_shop_list_page.do"
                },
                ajaxParam:function(){
                    var obj = {};
                    if($("#prov").val()) {
                        obj["prov"] = $("#prov").val();
                    }
                    if($("#type").val()) {
                        obj["type"] = $("#type").val();
                    }
                     if($("#city").val()) {
                        obj["city"] = $("#city").val();
                    }
                     if($("#area").val()) {
                        obj["area"] = $("#area").val();
                    }
                    if($("#name").val()) {
                        obj["name"] = $("#name").val();
                    }
                    return obj;
                },
                buttons:[{cmd:'add'},{cmd:'del',text:'删除',action:function (cmd,e,dt,node,config,tgobj) {
                        var data = {"ids":tgobj.checkIds};
                        ListPageManager.Tools.ajax({
                            url:"${ctx}/store_shop_del.do",
                            data:data,
                            success:function (e) {
                                if(e.success){
                                    ListPageManager.Popup.msg("删除成功",{},function () {
                                        tgobj.redraw();
                                    });
                                }else{
                                    ListPageManager.Popup.msg(e.message);
                                }
                            }
                        });

                    }}],
                addUrl:function(){return "${ctx}/store_shop_edit.do?type=" + $("#type").val()},
                updUrl:function(row,data,dataIndex){return "${ctx}/store_shop_edit.do?id=" + data.id + "&type=" + $("#type").val()},
                deleteUrl:function(row,data,dataIndex){return "${ctx}/store_shop_del.do?ids[]=" + data.id },
                rowCreatedCall:function(row,data,dataIndex){},
                withCheckColumn:{flg:true,key:"id"},
                columns:[
                    {title:"序号",data:"id"},
                    {title:"名称",data:"name"},
                    {title:"省份",data:"provName"},
                    {title:"城市",data:"cityName"},
                    {title:"区（县",data:"areaName"},
                    {title:"地址",data:"detail"},
                    {title:"电话",data:"tel"},
                    {title:"经纬度",render:function (ctx,status,data) {
                            return data.longitude + ',' + data.latitude;

                        }},
                    {title:"操作",toolcolinfo:[{cmd:"upd"},{"cmd":"del"}]}
                ]
            },$("#example"));
            $("#btnSubmit").on("click",function(){
                table.redraw();
            });
        });
        
        function altCitys(code){
			$("#city").html("<option value=''>请选择城市...</option>");
			
			var prov = $("#prov").val();
			if(prov!=''){
				$.get("/ajaxGetAreaMap.do",{code:prov,type:"city"},function(data){
					var arr = "";
					var selected = "";
					for(var obj in data.data){
						
						arr += "<option value='"+data.data[obj]["code"]+"'>"+data.data[obj]["name"]+"</option>";
					}
					$("#city").append(arr);
				},"json");
			}
		}
		
		function altAreas(cityCode,code){
			$("#area").html("<option value=''>请选择区/县...</option>");
			var city = $("#city").val();
			if(cityCode!=undefined){
				city = cityCode;
			}
			var arr = "";
			var selected = "";
			if(city!=''){
				$.get("/ajaxGetAreaMap.do",{code:city,type:"area"},function(data){
					var arr = [];
					var selected = "";
					for(var obj in data.data){
						if(code!=undefined && data.data[obj]["code"]==code){
							selected = "selected='selected'";
						}else{
							selected = "";
						}
						arr += "<option value='"+data.data[obj]["code"]+"' "+selected+">"+data.data[obj]["name"]+"</option>";
					}
					$("#area").append(arr);
				},"json");
			}
			
		}

    </script>
</body>
</html>
